<html>
    <head>
        <title>Page Title</title>
        <style media="screen">
            body {
                font-size: 12px;
            }
        </style>
    </head>
</body>
{* 从配置文件中读取变量，可以设置局部和全局，局部需要加上section  *}
{config_load file="global.conf" section="color"}
<div style="width:{#width#}px;background-color:{$smarty.config.color}">

<h1>Hello {$name}</h1><p>welcome to home!</p>

{* 保留变量 *}
{$smarty.get.username}
</div>

{* 变量调节器 *}
<h1>Hello {$name|upper}</h1><p>welcome to home!</p>
<h1>Hello {$name|upper|truncate:2}</h1><p>welcome to home!</p>

{* 自定义函数 *}
{hello line="5" content="hello"}

{* 自定义块 *}
{world line="5"}
sdadasdasdadasdasd
asdas
das
d
sd
asd
as
da
{/world}

{* 变量声明,第三种最方便 *}
{assign var="one" value="hello world"}
{assign "two" "this is two"}
{$three="aaaaaaaaaa"}
<p>{$three}</p>


{* if *}
{$var=1}
{if $var==2}
    if is succeed.
    {elseif $var==1}
        elseif is succeed.
{/if}


{* for *}
{for $var=1 to 5 step 2 max=3}
    {$var}
    {forelse}
    forelse is showed
{/for}


{* while *}
{$var1=0}
{while $var1 lt 10}
{$var1++} {* 要有退出条件，否则死循环 *} <br>
{/while}

{*以下内容可以用在 数据库查询数据上 *}

{* foreach *}
{$arr=['os'=>'linux','server'=>'apache']}
{foreach $arr as $key=>$value}
    {$key}{$value}<br>
{foreachelse}
数组不存在或数组为空
{/foreach}

{* section *}
{$arr1=['os','linux','server','apache']}
{section name="one" loop=$arr1}
    {* <h1>{$arr1[$smarty.section.one.index]}</h1> *}
    <h1>{$arr1[one]}</h1>
{/section}
</body>
</html>
